package com.zhuchaooasystem.utils;

import android.text.TextUtils;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Locale;

/**
 * @author yinsi
 *         <p/>
 *         日期工具类
 */
public class CalendarUtils {

    /**
     * 获取当前时间（并设置格式）
     *
     * @return
     */
    public static String getNow(String format) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTimeInMillis(System.currentTimeMillis());
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat(format);
        return simpleDateFormat.format(calendar.getTime());
    }

    /**
     * 录音时间转换
     *
     * @param millis
     * @return
     */
    public static String duration2timeString(int millis) {
        String time = "";
        int m = millis / 60;
        int s = millis % 60;
        if (m < 10) {
            time += "0" + m;
        } else {
            time += "" + m;
        }
        if (s < 10) {
            time += ":0" + s;
        } else {
            time += ":" + s;
        }
        return time;
    }

    /**
     * 转化毫秒数为日期，格式为 yyyy/MM/dd
     *
     * @return
     */
    public static String formatSysMills(String mills) {
        String date = "";
        try {
            if (!TextUtils.isEmpty(mills)) {
                SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm", Locale.CHINA);
                date = simpleDateFormat.format(Long.parseLong(mills.substring(mills.indexOf("(") + 1, mills.indexOf(")"))));
            }
        } catch (Exception e) {
        }
        return date;
    }


}
